package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProStock;
import com.ruoyi.mes.service.IProStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品库存Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "产品库存")
@RestController
@RequestMapping("/mes/stock")
public class ProStockController extends BaseController
{
    @Autowired
    private IProStockService proStockService;

    /**
     * 查询产品库存列表
     */
    @ApiOperation(value = "查询产品库存列表")
    @PreAuthorize("@ss.hasPermi('mes:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProStock proStock)
    {
        startPage();
        List<ProStock> list = proStockService.selectProStockList(proStock);
        return getDataTable(list);
    }

    /**
     * 导出产品库存列表
     */
    @ApiOperation(value = "导出产品库存列表")
    @PreAuthorize("@ss.hasPermi('mes:stock:export')")
    @Log(title = "产品库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProStock proStock)
    {
        List<ProStock> list = proStockService.selectProStockList(proStock);
        ExcelUtil<ProStock> util = new ExcelUtil<ProStock>(ProStock.class);
        util.exportExcel(response, list, "产品库存数据");
    }

    /**
     * 获取产品库存详细信息
     */
    @ApiOperation(value = "获取产品库存详细信息")
    @PreAuthorize("@ss.hasPermi('mes:stock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(proStockService.selectProStockById(id));
    }

    /**
     * 新增产品库存
     */
    @ApiOperation(value = "新增产品库存")
    @PreAuthorize("@ss.hasPermi('mes:stock:add')")
    @Log(title = "产品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProStock proStock)
    {
        return proStockService.insertProStock(proStock);
    }

    /**
     * 修改产品库存
     */@ApiOperation(value = "修改产品库存")
    @PreAuthorize("@ss.hasPermi('mes:stock:edit')")
    @Log(title = "产品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProStock proStock)
    {
        return toAjax(proStockService.updateProStock(proStock));
    }

    /**
     * 删除产品库存
     */
    @ApiOperation(value = "删除产品库存")
    @PreAuthorize("@ss.hasPermi('mes:stock:remove')")
    @Log(title = "产品库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proStockService.deleteProStockByIds(ids));
    }
}
